﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DTO.Models
{
    public class VoteProvider
    {
        private CITDBDataContext db = new CITDBDataContext();

        //insert
        public bool insert(VOTE vote)
        {
            try
            {
                db.VOTEs.InsertOnSubmit(vote);
                save();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool checkHaveVote(int surveyId, string ip) 
        {
            bool flag = false;
            try
            {
                VOTE[] query = (from c in db.VOTEs where c.SurveyId == surveyId && c.Ip == ip select c).ToArray();
                if (query.Length > 0)
                    flag = true;
            }
            catch
            {
                flag = false;
            }
            return flag;
        }

        //save
        public void save()
        {
            if (db != null)
                db.SubmitChanges();
        }

    }
}
